/*
 * @Author: wsy
 * @Date: 2022-05-11 15:29:42
 * @Last Modified by: wsy
 * @Last Modified time: 2022-05-14 09:35:37
 */
import tsgDistData from "@/assets/mapData/tieShanGangDistrict.json";
// import nanKangTownData from "@/assets/mapData/nanKangTown.json";
// import xingGangTownData from "@/assets/mapData/xingGangTown.json";
// import yingPanTownData from "@/assets/mapData/yingPanTown.json";
import request from "@/utils/request";

// data { zoom, location }
export const getMapInfo = (data = {}, townList = []) => {
    let res = {};
    const zoom = data.zoom || tsgDistData.zoom;
    const location = data.location || tsgDistData.center;
    if (zoom <= 12) {
        // 显示区级覆盖层和镇级Mark点
        res = {
            code: 0,
            data: {
                overlayData: [
                    // {
                    //     id: 0,
                    //     name: "铁山港",
                    //     ...tsgDistData,
                    //     fillColor: "#CCF3FF",
                    //     fillOpacity: 0.05,
                    //     child: { zoom: 13 },
                    // },
                ],
                zoom,
                location,
                markerData: [],
                condition: [0, 12], // 请求条件，用于减少前端项后端请求
            },
            message: "成功",
        };
        const fillColors = ["#ff0000", "#00ff00", "#0000ff"];
        res.data.overlayData = townList.map((item, index) => {
            return {
                id: 0,
                name: "铁山港",
                center: tsgDistData.center,
                zoom: tsgDistData.zoom,
                polygons: JSON.parse(item.coordinate),
                fillColor: fillColors[index],
                fillOpacity: 0.05,
                child: { zoom: 13 },
            };
        });
    } else {
        res = {
            code: 0,
            data: {
                zoom,
                location,
                markerData: [],
                condition: [13, 20],
            },
            message: "成功",
        };
        const fillColors = ["#ff0000", "#00ff00", "#0000ff"];
        res.data.overlayData = townList.map((item, index) => {
            const centerArr = item.center.split(",");
            return {
                id: item.id,
                name: item.name,
                center: { lat: centerArr[0], lng: centerArr[1] },
                zoom: item.zoom,
                polygons: JSON.parse(item.coordinate),
                fillColor: fillColors[index],
                fillOpacity: 0.05,
                parent: { zoom: 12 },
            };
        });
    }
    return new Promise((resolve) => {
        resolve(res);
    });
};

export function getTownList(params) {
    return request({
        url: "/zz/datav/grid/town_list",
        method: "get",
        params,
    });
}

export function getVillageList(params) {
    return request({
        url: "/zz/datav/grid/village_list",
        method: "get",
        params,
    });
}

export function getVillageChildList(params) {
    return request({
        url: "/zz/datav/grid/village_children_list",
        method: "get",
        params,
    });
}

export function getCellList(params) {
    return request({
        url: "/zz/datav/grid/cell_list",
        method: "get",
        params,
    });
}

export function getSliceParents(params) {
    return request({
        url: "/zz/datav/grid/get_parent_ids",
        method: "get",
        params,
    });
}
